import mitt from 'mitt'
import { onMounted, onUnmounted } from 'vue'

export const bus = mitt()

export function useBusOn(name, func) {
  onMounted(() => {
    console.log('监听[' + name + ']事件')
    bus.on(name, func)
  })
  onUnmounted(() => {
    console.log('卸载[' + name + ']事件')
    bus.off(name, func)
  })
}

export function busEmit(name, obj) {
  bus.emit(name, obj)
}

export function busOn(name, func) {
  bus.on(name, func)
}


export function busOff(name, func) {
  bus.off(name, func)
}

export function useBusEmmit(name, obj) {
  bus.emit(name, obj)
}